#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<string.h>

int main() 
{
	char str[1000];
	fgets(str, sizeof(str), stdin);
	int k = 0;
	scanf("%d", &k);
	int len = strlen(str);
	for (int i = 0; i < (len - 1) / 2; i++)
	{
		int t = str[i];
		str[i] = str[len - 2 - i];
		str[len - 2 - i] = t;
	}
	for (int i = 0; i < (len - 1 - k) / 2; i++)
	{
		int t = str[i];
		str[i] = str[len - 2 - k - i];
		str[len - 2 - k - i] = t;
	}
	for (int i = len - 1 - k; i < len - 1; i++) {
		int t = str[i];
		str[i] = str[len - 2];
		str[len - 2] = t;
	}
	for (int i = 0; i < len; i++)
	{
		printf("%c", str[i]);
	}
	return 0;
}